package com.droidclaimsurveyor.bl;

import android.content.Context;

import com.droidclaimsurveyor.dal.SurveyorDal;
import com.droidclaimsurveyor.dal.DatabaseLoader;
import com.droidclaimsurveyor.helper.asyntask.ICompleteListener;
import com.droidclaimsurveyor.model.SurveyorModel;

public class ServeyorBl {
	ICompleteListener listener;
	

	public ServeyorBl(ICompleteListener listener) {
		this.listener = listener;
	}

	public String GetAllSurveyor(String surveyorId) {
		DatabaseLoader<SurveyorModel, String> dbLoader = new DatabaseLoader<SurveyorModel, String>(
				(Context) listener, "GetAllSurveyor");
		String claimInfoTask = SurveyorDal.GetAllSurveyorId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		SurveyorDal dal = new SurveyorDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(surveyorId);
		
		return claimInfoTask;
	}
	
	public String GetLastSurveyor(String surveyorId) {
		DatabaseLoader<SurveyorModel, String> dbLoader = new DatabaseLoader<SurveyorModel, String>(
				(Context) listener, "GetLastClaimInfo");
		String claimInfoTask = SurveyorDal.GetLastSurveyorId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		SurveyorDal dal = new SurveyorDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(surveyorId);
		
		return claimInfoTask;
	}
	
	public String GetSurveyorByRowId(long rowId) {
		DatabaseLoader<SurveyorModel, String> dbLoader = new DatabaseLoader<SurveyorModel, String>(
				(Context) listener, "GetClaimInfoByRowId");
		String claimInfoTask = SurveyorDal.GetSurveyorByRowId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		SurveyorDal dal = new SurveyorDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(Long.toString(rowId));
		
		return claimInfoTask;
	}

	public long addSurveyor(SurveyorModel data) {
		SurveyorDal dal = new SurveyorDal((Context)listener);
		dal.open();
		long result = dal.add(data);
		dal.close();
		
		return result;
	}

	public boolean updateSurveyor(long rowIndex, SurveyorModel data) {
		SurveyorDal dal = new SurveyorDal((Context)listener);
		dal.open();
		boolean result = dal.update(rowIndex,data);
		dal.close();
		return result;
	}

	public boolean removeSurveyor(long claimId) {		
		SurveyorDal dal = new SurveyorDal((Context)listener);
		dal.open();
		boolean result =  dal.remove(claimId);
		dal.close();
		return result;
	}	
}
